package com.hzw.preview.test02;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class AppCore {
    public static void main(String[] args) throws Exception {
        // TODO
        // 1. 通过反射得到 CustomerService 类的实例 c
        // 2. 调用实例 c 的 say 方法并正确输出结果

        Class<?> c = Class.forName("com.hzw.preview.test02.CoreService");
        Object o = c.newInstance();

        Field userService = c.getDeclaredField("userService");
        userService.setAccessible(true);
        Class<?> a1 = Class.forName("com.hzw.preview.test02.UserService");
        Object o1 = a1.newInstance();
        userService.set(o,o1);

        Field orderService = c.getDeclaredField("orderService");
        orderService.setAccessible(true);
        Class<?> a2 = Class.forName("com.hzw.preview.test02.OrderService");
        Object o2 = a2.newInstance();
        orderService.set(o,o2);

        Field customerService = c.getDeclaredField("customerService");
        customerService.setAccessible(true);
        Class<?> a3 = Class.forName("com.hzw.preview.test02.CustomerService");
        Object o3 = a3.newInstance();
        customerService.set(o,o3);

        Method say = c.getMethod("say");
        say.invoke(o);

    }

}
